package com.example.anew.journey.mynewjourney.firstchangelogic.firstChangeHistoricalRecordCardiacDetection;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.anew.journey.mynewjourney.R;
import com.example.anew.journey.mynewjourney.customview.MyCardiacProgessView;
import com.example.anew.journey.mynewjourney.firstchangelogic.firstChangeHistoricalRecordCardiacDetection.persenter.FirstChangeHistoricalRecordCardiacDetectionPersenter;
import com.example.anew.journey.mynewjourney.firstchangelogic.firstChangeHistoricalRecordCardiacDetection.view.FirstChangeHistoricalRecordCardiacDetectionView;
import com.example.anew.journey.mynewjourney.utils.AntiShake;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.jesse.nativelogger.NLogger;

/**
 * 杭州惟君医疗科技有限公司17
 * Created by 20433 on 2018/3/21
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class FirstChangeHistoricalRecordCardiacDetectionActvity extends AppCompatActivity implements View.OnClickListener, FirstChangeHistoricalRecordCardiacDetectionView {

    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_tv_heart_rate)
    TextView activityFirstChangeHistorcalRecordCardiacDetectionTvHeartRate;
    @Bind(R.id.activity_first_change_main_home_page_rl_my_devics)
    RelativeLayout activityFirstChangeMainHomePageRlMyDevics;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_iv_left_linkage)
    ImageView activityFirstChangeHistorcalRecordCardiacDetectionIvLeftLinkage;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_tv_titile_name)
    TextView activityFirstChangeHistorcalRecordCardiacDetectionTvTitileName;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_iv_search_bt)
    ImageView activityFirstChangeHistorcalRecordCardiacDetectionIvSearchBt;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.app_bar)
    AppBarLayout appBar;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_tv_analysis_report)
    TextView activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_my_cardiac_progess_view)
    MyCardiacProgessView activityFirstChangeHistorcalRecordCardiacDetectionMyCardiacProgessView;
    @Bind(R.id.activity_first_change_historcal_record_cardiac_detection_tv_advice)
    TextView activityFirstChangeHistorcalRecordCardiacDetectionTvAdvice;
    private AntiShake util;
    private FirstChangeHistoricalRecordCardiacDetectionPersenter mFirstChangeHistoricalRecordCardiacDetectionPersenter = new FirstChangeHistoricalRecordCardiacDetectionPersenter(this);
    private RelativeLayout rl_weixin;
    private RelativeLayout rl_pengyouquan;
    private RelativeLayout rl_qq;
    private RelativeLayout rl_weibo;
    private TextView tv_cancle;
    private String[] arr = new String[]{"测量低于正常范围，建议宝妈多测几次，如果多次测量结果仍是过慢，请及时咨询医生",
            "宝宝胎心在正常范围，宝妈继续保持良好的生活习惯，等待宝宝的到来",
            "测量高于正常范围，建议宝妈多测几次，如果多次测量结果仍是过快，请及时咨询医生"};
    // private MyCardiacProgessView my_cardiac_progess_view;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_change_historcal_record_cardiac_detection);
        ButterKnife.bind(this);
        util = new AntiShake();

        activityFirstChangeHistorcalRecordCardiacDetectionIvLeftLinkage.setOnClickListener(this);
        activityFirstChangeHistorcalRecordCardiacDetectionIvSearchBt.setOnClickListener(this);
        Intent intent = getIntent();
        String my_test_date = intent.getStringExtra("my_test_date");
        String my_test_desc = intent.getStringExtra("my_test_desc");
        activityFirstChangeHistorcalRecordCardiacDetectionTvAdvice.setText(my_test_desc);
        if (TextUtils.isEmpty(my_test_date)) {
            activityFirstChangeHistorcalRecordCardiacDetectionTvHeartRate.setText("---");
        }else{
            activityFirstChangeHistorcalRecordCardiacDetectionTvHeartRate.setText(my_test_date);
        }

        try {
            int test_date = Integer.parseInt(my_test_date.trim());
            NLogger.e("TAG", " test_date=========== " + test_date);
            if (test_date < 120) {
                activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport.setText(arr[0]);
            } else if (test_date > 180) {
                activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport.setText(arr[2]);
            } else {
                activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport.setText(arr[1]);
            }
            activityFirstChangeHistorcalRecordCardiacDetectionMyCardiacProgessView.start(test_date);
        } catch (NumberFormatException e) {
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.activity_first_change_historcal_record_cardiac_detection_iv_left_linkage:
                finish();
                break;
            case R.id.activity_first_change_historcal_record_cardiac_detection_iv_search_bt:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClickeShared(this);
                break;
            case R.id.historcal_record_cardiac_detection_pupo_rl_weixin:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClickShareWeixin();
                break;
            case R.id.historcal_record_cardiac_detection_pupo_rl_pengyouquan:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClickSharePengyouquan();
                break;
            case R.id.historcal_record_cardiac_detection_pupo_rl_qq:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClickShareQQ();
                break;
            case R.id.historcal_record_cardiac_detection_pupo_rl_weibo:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClickShareWeibo();
                break;
            case R.id.historcal_record_cardiac_detection_pupo_tv_cancle:
                mFirstChangeHistoricalRecordCardiacDetectionPersenter.onClicksharedCancel();
                break;
        }
    }

    //获取心率
    @Override
    public String getHeartRate() {
        return activityFirstChangeHistorcalRecordCardiacDetectionTvHeartRate.getText().toString().trim();
    }

    //设置心率
    @Override
    public void setHeartRate(String str) {
        activityFirstChangeHistorcalRecordCardiacDetectionTvHeartRate.setText(str);
    }

    // 获取分析报告
    @Override
    public String getAnalysisReport() {
        return activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport.getText().toString().trim();
    }

    //设置分析报告
    @Override
    public void setAnalysisReport(String str) {
        activityFirstChangeHistorcalRecordCardiacDetectionTvAnalysisReport.setText(str);
    }

    // 设置进度
    @Override
    public void setMyProgess(int progess) {
        activityFirstChangeHistorcalRecordCardiacDetectionMyCardiacProgessView.start(70);
    }

    // 获取建议
    @Override
    public String getAdvice() {
        return activityFirstChangeHistorcalRecordCardiacDetectionTvAdvice.getText().toString().trim();
    }

    //设置建议
    @Override
    public void setAdvice(String str) {
        activityFirstChangeHistorcalRecordCardiacDetectionTvAdvice.setText(str);
    }

    // 显示提示Toast信息
    @Override
    public void showToastInformation(String str) {
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }

    //分享取消
    @Override
    public void sharedCancel() {

    }

    @Override
    public void findPupoView(View mview) {
        rl_weixin = mview.findViewById(R.id.historcal_record_cardiac_detection_pupo_rl_weixin);
        rl_pengyouquan = mview.findViewById(R.id.historcal_record_cardiac_detection_pupo_rl_pengyouquan);
        rl_qq = mview.findViewById(R.id.historcal_record_cardiac_detection_pupo_rl_qq);
        rl_weibo = mview.findViewById(R.id.historcal_record_cardiac_detection_pupo_rl_weibo);
        tv_cancle = mview.findViewById(R.id.historcal_record_cardiac_detection_pupo_tv_cancle);

        rl_weixin.setOnClickListener(this);
        rl_pengyouquan.setOnClickListener(this);
        rl_qq.setOnClickListener(this);
        rl_weibo.setOnClickListener(this);
        tv_cancle.setOnClickListener(this);
    }

    // TODO 获取焦点
    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);

    }

    // TODO 失去焦点  可以进行一些轻量级的存储数据和去初始化工作
    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);

    }
}
